<?php
namespace app\admin\controller;
use think\Db;
//业主管理
class Ower extends Base{
	//申请为业主的列表
	public function apply_list(){
		$stat		=!empty(input('stat')) ? input('stat') : '';
		$phone		=!empty(input('phone')) ? input('phone') : ''; 
    	$stime		=!empty(input('stime')) ? input('stime') : 0;
    	$etime		=!empty(input('etime')) ? input('etime') : 0;
		$map['del']=['NEQ',1];	//没有绑定商品
		
		if(!empty($stat)){
			$map['stat']=['EQ',$stat];
		}
		if(!empty($phone)){
			$map['phone']=['like','%'.$phone.'%'];	//根据生成批次筛选
		} 
		
		if(!empty($stime) && !empty($etime)){
    		$s=strtotime($stime);
			$e=strtotime($etime);
    		$map['ctime']=['between',[$s,$e]];
    	}elseif(!empty($stime)){
    		$s=strtotime($stime);
    		$map['ctime']=['EGT',$s];	
    	}elseif(!empty($etime)){
    		$e=strtotime($etime);
			$map['ctime']=['ELT',$e];
    	}
		
    	$rel=Db::name('applyOwer')
		->where($map)
		->order('ctime desc,id desc')
		->paginate(10,false,['query'=>[
			'stat'      => $stat,
			'phone'		=>$phone,
			'stime'		=>$stime,
			'etime'		=>$etime
		]]);
		$this->assign('data',$rel);
		$this->assign('page',$rel->render());
		$this->assign('empty',"<tr><td class='empty' colspan='10'>当前没有数据 </td></tr>");
		$this->assign(['stat'=>$stat,'phone'=>$phone,'stime'=>$stime,'etime'=>$etime]);
		return $this->fetch();
	}
	//租客列表
	public function ower_list(){
		$phone		=!empty(input('phone')) ? input('phone') : '';
		$map['del']=['NEQ',1];	//没有绑定商品
		$map['stat']=['EQ',1];	//没有绑定商品
		$map['type']=['EQ',3];	//没有绑定商品
		
		if(!empty($phone)){
			$map['phone']=['like','%'.$phone.'%'];	//根据生成批次筛选
		}
		
    	$rel=Db::name('users')
		->where($map)
		->order('ctime desc,id desc')
		->paginate(10,false,['query'=>[
			'phone'		=>$phone
		]]);
		$this->assign('data',$rel);
		$this->assign('page',$rel->render());
		$this->assign('empty',"<tr><td class='empty' colspan='10'>当前没有数据 </td></tr>");
		$this->assign(['phone'=>$phone]);
		return $this->fetch();
	}
	//处理成为业主的申请
	public function do_apply(){
		$apply_id=input('id');
		$val=input('val');
		if($val==2){	//同意
			$apply=Db::name('applyOwer')->where('id',$apply_id)->find();
			Db::name('users')->where('id',$apply['uid'])->update(['type'=>3]);
		}
		
		$rel=Db::name('applyOwer')->where('id',$apply_id)->update(['stat'=>$val]);
		if(!$rel){
			return rel(-1,'处理失败');
		}else{
			return rel(1,'处理成功');
		}
	}
}
